﻿CREATE PROC copyquyenuser 
@IDPhanNhomNguoiDung int,    
@ViTri int,    
@ChuongTrinh int,    
@NhomMenu int,
@ChuoiIDPhanNhomNguoiDung varchar(8000)    
as
/*
declare @bangtam table
(
ID   bigint   NOT NULL,
IDPhanNhomNguoiDung   int  NULL,
IDCapQuyen   int  NULL,
IDPhanNhomMenu   int  NULL,
Quyen_CapNhat   bit  NULL,
Quyen_Xem   bit  NULL,
Quyen_Xoa   bit  NULL
)
insert into @bangtam(ID,Quyen_CapNhat,Quyen_Xem,Quyen_Xoa ,IDPhanNhomNguoiDung,IDCapQuyen,IDPhanNhomMenu )
select ID,Quyen_CapNhat,Quyen_Xem,Quyen_Xoa ,IDPhanNhomNguoiDung,IDCapQuyen,IDPhanNhomMenu 
from dbo.copymenutheonhom (@IDPhanNhomNguoiDung , @ViTri ,  @ChuongTrinh , @NhomMenu  ) 
*/
declare @chuoi varchar(8000)
set @chuoi=@ChuoiIDPhanNhomNguoiDung
while LEN(@chuoi)>0        
begin        

declare @IDU   bigint   
declare @IDPhanNhomNguoiDungU   int  
declare @IDCapQuyenU   int  
declare @IDPhanNhomMenuU   int  
declare @Quyen_CapNhatU   bit  
declare @Quyen_XemU   bit  
declare @Quyen_XoaU   bit  
declare ds CURSOR KEYSET         
for  
select ID,Quyen_CapNhat,Quyen_Xem,Quyen_Xoa ,IDPhanNhomNguoiDung,IDCapQuyen,IDPhanNhomMenu 
from dbo.copymenutheonhom (@IDPhanNhomNguoiDung , @ViTri ,  @ChuongTrinh , @NhomMenu  )      
OPEN ds       
FETCH NEXT FROM ds INTO @IDU,@Quyen_CapNhatU,@Quyen_XemU,@Quyen_XoaU ,@IDPhanNhomNguoiDungU,@IDCapQuyenU,@IDPhanNhomMenuU  
WHILE @@FETCH_STATUS = 0         
Begin        
        
update QuanTri_EditUserRoleInGroup  
set Quyen_CapNhat=@Quyen_CapNhatU,Quyen_Xem=@Quyen_XemU,Quyen_Xoa=@Quyen_XoaU
Where IDCapQuyen=@IDCapQuyenU and IDPhanNhomMenu=@IDPhanNhomMenuU 
and IDPhanNhomNguoiDung=cast(SUBSTRING(@chuoi,0,CHARINDEX(',',@chuoi)) as int)
        
FETCH NEXT FROM ds INTO @IDU,@Quyen_CapNhatU,@Quyen_XemU,@Quyen_XoaU ,@IDPhanNhomNguoiDungU,@IDCapQuyenU,@IDPhanNhomMenuU             
END --ket thuc xu ly menu con        
CLOSE ds       
DEALLOCATE ds
    
--insert into @bangtam (MaBB) values (SUBSTRING(@chuoi,0,CHARINDEX(',',@chuoi)))   
--select * from QuanTri_EditUserRoleInGroup     
set @chuoi=SUBSTRING(@chuoi,CHARINDEX(',',@chuoi)+1,LEN(@chuoi)-CHARINDEX(',',@chuoi))        
end
select ErrCode=1